package com.core.ingenium.view;

import javax.el.ELContext;
import javax.el.ExpressionFactory;
import javax.el.ValueExpression;
import javax.faces.application.Application;
import javax.faces.context.FacesContext;


/**
 * Helper class for Using EL in JSF 1.1 (JDeveloper 10.1.3)
 */
public class EL {

    public static Object get(String expr) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        Application app = facesContext.getApplication();
        ExpressionFactory elFactory = app.getExpressionFactory();
        ELContext elContext = facesContext.getELContext();
        ValueExpression valueExp = elFactory.createValueExpression(elContext, expr, Object.class);
        return valueExp.getValue(elContext);
    }

    public static void set(String expr, Object value) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        Application app = facesContext.getApplication();
        ExpressionFactory elFactory = app.getExpressionFactory();
        ELContext elContext = facesContext.getELContext();
        ValueExpression valueExp = elFactory.createValueExpression(elContext, expr, Object.class);
        valueExp.setValue(elContext, value);
    }
}